<?php 
	include_once dirname(dirname(dirname(__FILE__))).'/inc/bootConfig.php';
	include_once '../checkLogin.php';
	if($_POST['editsubmit']){
		if(isset($_POST['oldmod']) && is_array($_POST)){
			foreach ($_POST['oldmod'] as $k=>$v){
				$upd['z_name']=$v['name'];
				$upd['z_grade']=$v["order"];
				$upd['z_url']=$v["url"];
				$upd['z_showmod'] = $v['showmod'];
				$upd['z_show']=$v["show"];
				$tablename = 'zjx_module_admin';
				Module_Edit::update($tablename,$upd,'z_id='.$k);
			}
		}
		if(isset($_POST['newmod']) && is_array($_POST)){
			foreach ($_POST['newmod'] as $k=>$value){
				foreach ($value as $v){
					$upd['z_name']=$v['name'];
					$upd['z_grade']=$v["order"];
					$upd['z_url']=$v["url"];
					$upd['z_showmod']=$v["showmod"];
					$upd['z_show']=$v["show"];
					$upd['z_belong']=$k;
					$tablename = 'zjx_module_admin';
					Module_Edit::insert($tablename,$upd);
				}
			}
		}
		Cache_Filecache::delFileCache();
	}
	$mainmod = Module_Select::getMainModule();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查看模块</title>
<link rel="stylesheet" type='text/css' href='../Public/static/css/admincp/admincp.css'>
</head>
<body>
<table id="tips" class="tb tb2 ">
	<tbody>
		<tr>
			<th class="partition">技巧提示</th>
		</tr>
		<tr>
			<td class="tipsblock">
			<ul id="tipslis">
				<li>模块即为导航上显示的部分，版块即为导航上部分的下属模块</li>
				<li>模块显示方式可以方便控制头部导航和脚部导航的显示效果</li>
				<li>模块显示顺序数字越小越靠前显示</li>
				<li>首页缩略展示决定首页四个版块的展示</li>
				<li>模块类型约定模块最终的显示效果</li>
				<li>模块的最大为四个层级</li>
			</ul>
			</td>
		</tr>
	</tbody>
</table>
<form action="" method='post'>
<table class="tb tb2 ">
	<tbody>
		<tr class="header">
			<th></th>
			<th width="100px">显示顺序</th>
			<th>版块名称-模块类型-显示方式-首页缩略展示</th>
			<th></th>
		</tr>
	</tbody>
	<?php 
		foreach ($mainmod as $v){
			$sonmod = Module_Select::getSonModuleById($v['z_id']);
	?>
	<tbody>
		<tr class="hover">
			<td class="td25">
				<a class="shousuo" href="javascript:;">[-]</a>
			</td>
			<td class="td25">
				<input type="text" value="<?php echo $v['z_grade']?>" name="oldmod[<?php echo $v['z_id']?>][order]" class="txt">
			</td>
			<td colspan='6'>
				<div class="parentboard">
					<input type="text" class="txt" value="<?php echo $v['z_name']?>" name="oldmod[<?php echo $v['z_id']?>][name]">
					<?php echo putselect('oldmod['.$v['z_id'].'][url]', $monGroup,$v['z_url']);?>
					<?php echo putselect('oldmod['.$v['z_id'].'][showmod]', array(2=>'显示',1=>'隐藏',3=>'在脚部隐藏'),$v['z_showmod']);?>
					<?php echo putselect('oldmod['.$v['z_id'].'][show]', array(2=>'展示',1=>'不展示'),$v['z_show']);?>
				</div>
			</td>
			<td colspan='4'>
				<a class="act" title="编辑本模块设置" href="adminMod.php?e=edit&id=<?php echo $v['z_id']?>">编辑</a>
				<a class="act" title="删除本模块及其中所有内容" href="adminMod.php?e=del&id=<?php echo $v['z_id']?>" args="del,<?php echo $v['z_id']?>">删除</a>
			</td>
		</tr>
		<?php 
			if(is_array($sonmod)&&count($sonmod)>0){
				foreach ($sonmod as $val){
					$sonmod2 = Module_Select::getSonModuleById($val['z_id']);
		?>
		<tr class='sonmod'>
			<td></td>
			<td class="td25"><input type="text" value="<?php echo $val['z_grade']?>" name="oldmod[<?php echo $val['z_id']?>][order]" class="txt"></td>
			<td colspan="6">
				<div class="board">
					<input type="text" class="txt" size="20" value="<?php echo $val['z_name']?>" name="oldmod[<?php echo $val['z_id']?>][name]">
					<a class="addchildboard" parent='<?php echo $val['z_id']?>' href="###">添加子版块</a>
					<?php echo putselect('oldmod['.$val['z_id'].'][url]', $monGroup,$val['z_url']);?>
				</div>
			</td>
			<td colspan='4'>
				<a class="act" title="编辑本模块设置" href="adminMod.php?e=edit&id=<?php echo $val['z_id']?>">编辑</a>
				<a class="act" title="删除本模块及其中所有内容" href="adminMod.php?e=del&id=<?php echo $val['z_id']?>" args="del,<?php echo $val['z_id']?>">删除</a>
			</td>
		</tr>
		<?php 
				if(is_array($sonmod2)&&count($sonmod2)>0){
					foreach ($sonmod2 as $value) {
						$sonmod3 = Module_Select::getSonModuleById($value['z_id']);
		?>
					<tr class="hover sonmod">
						<td class="td25"></td>
						<td class="td25"><input type="text" value="<?php echo $value['z_grade']?>" name="oldmod[<?php echo $value['z_id']?>][order]" class="txt"></td>
						<td  colspan="6">
							<div class="lastchildboard" id="cb_44">
								<input type="text" class="txt" value="<?php echo $value['z_name']?>" name="oldmod[<?php echo $value['z_id']?>][name]">
								<a class="addfourchildboard" parent='<?php echo $value['z_id']?>' href="###">添加子版块</a>
								<?php echo putselect('oldmod['.$value['z_id'].'][url]', $monGroup,$value['z_url']);?>	
							</div>
						</td>
						<td width="160"  colspan="4">
							<a class="act" title="编辑本版块设置" href="adminMod.php?e=edit&id=<?php echo $value['z_id']?>">编辑</a>
							<a class="act" title="删除本版块及其中所有帖子" href="adminMod.php?e=del&id=<?php echo $value['z_id']?>">删除</a>
						</td>
					</tr>
					<?php 
							if(is_array($sonmod3)&&count($sonmod3)>0){
								foreach ($sonmod3 as $values) {
					?>
								<tr class="hover sonmod">
									<td class="td25"></td>
									<td class="td25"><input type="text" value="<?php echo $values['z_grade']?>" name="oldmod[<?php echo $values['z_id']?>][order]" class="txt"></td>
									<td  colspan="6">
										<div class="fourchildboard" id="cb_44">
											<input type="text" class="txt" value="<?php echo $values['z_name']?>" name="oldmod[<?php echo $values['z_id']?>][name]">
											<?php echo putselect('oldmod['.$values['z_id'].'][url]', $monGroup,$values['z_url']);?>	
										</div>
									</td>
									<td width="160"  colspan="4">
										<a class="act" title="编辑本版块设置" href="adminMod.php?e=edit&id=<?php echo $values['z_id']?>">编辑</a>
										<a class="act" title="删除本版块及其中所有帖子" href="adminMod.php?e=del&id=<?php echo $values['z_id']?>">删除</a>
									</td>
								</tr>
		<?php 
								}
							}
						}
					}
				}
			}
		?>
		<tr>
			<td></td>
			<td colspan="4">
				<div class="lastboard"><a class="addtr addtwomod" parent='<?php echo $v['z_id']?>' href="###">添加新版块</a></div>
			</td>
			<td>&nbsp;</td>
		</tr>
	</tbody>
	<?php }?>
	<tbody>
		<tr>
			<td></td>
			<td colspan='11'>
				<div><a class="addtr" id="addonemod" onclick="" href="###">添加新模块</a></div>
			</td>
		</tr>
		<tr>
			<td colspan="12">
			<div class="fixsel"><input type="submit" value="提交"
				title="按 Enter 键可随时提交你的修改" name="editsubmit" id="submit_editsubmit"
				class="btn"></div>
			</td>
		</tr>
	</tbody>
</table>
</form>
</body>
</html>
<script src="../Public/static/js/jquery.js"></script>
<script>
var i=0;
$('#addonemod').click(function(){
	i++
	$(this).parents('tr').before('<tr><td><p class="pointer" onclick="delmod(this)">【删除】</p></td><td class="td25"><input type="text" value="0" name="newmod[0]['+i+'][order]" class="txt"></td><td colspan="10"><input type="text" class="txt" size="20" value="新模块名称" name="newmod[0]['+i+'][name]"><select name="newmod[0]['+i+'][url]"><option value="showmod">模块展示</option><option value="showtit">标题展示</option><option value="content">内容展示</option><option value="product">产品展示</option><option value="msgboard">留言板</option></select>&nbsp;<select name="newmod[0]['+i+'][showmod]"><option value="2">显示</option><option value="1">隐藏</option><option value="3">在脚部隐藏</option></select>&nbsp;<select name="newmod[0]['+i+'][show]"><option value="1">不展示</option><option value="2">展示</option></select></td></tr>')
})
$('.addtwomod').click(function(){
	var p=$(this).attr('parent')
	i++
	$(this).parents('tr').before('<tr><td colspan="1"><p class="pointer" onclick="delmod(this)">【删除】</p></td><td colspan="1" class="td25"><input type="text" value="0" name="newmod['+p+']['+i+'][order]" class="txt"></td><td colspan="5"><div class="board"><input type="text" class="txt" size="20" value="新版块名称" name="newmod['+p+']['+i+'][name]"><select name="newmod['+p+']['+i+'][url]"><option value="showmod">模块展示</option><option value="showtit">标题展示</option><option value="content">内容展示</option><option value="product">产品展示</option><option value="msgboard">留言板</option></select></div></td></tr>');
})
$('.addchildboard').click(function(){
	var p=$(this).attr('parent')
	i++
	$(this).parents('tr').after('<tr><td colspan="1"><p class="pointer" onclick="delmod(this)">【删除】</p></td><td colspan="1" class="td25"><input type="text" value="0" name="newmod['+p+']['+i+'][order]" class="txt"></td><td colspan="5"><div class="childboard"><input type="text" class="txt" size="20" value="新版块名称" name="newmod['+p+']['+i+'][name]"><select name="newmod['+p+']['+i+'][url]"><option value="showmod">模块展示</option><option value="showtit">标题展示</option><option value="content">内容展示</option><option value="product">产品展示</option><option value="msgboard">留言板</option></select></div></td></tr>');
})
$('.addfourchildboard').click(function(){
	var p=$(this).attr('parent')
	i++
	$(this).parents('tr').after('<tr><td colspan="1"><p class="pointer" onclick="delmod(this)">【删除】</p></td><td colspan="1" class="td25"><input type="text" value="0" name="newmod['+p+']['+i+'][order]" class="txt"></td><td colspan="5"><div class="fourchildboard"><input type="text" class="txt" size="20" value="新版块名称" name="newmod['+p+']['+i+'][name]"><select name="newmod['+p+']['+i+'][url]"><option value="showmod">模块展示</option><option value="showtit">标题展示</option><option value="content">内容展示</option><option value="product">产品展示</option><option value="msgboard">留言板</option></select></div></td></tr>');
})
$('.shousuo').click(function(){
	$(this).parents('tbody').children('.sonmod').toggle()
	if($(this).html()=='[-]'){
		$(this).html('[+]')
	}else{
		$(this).html('[-]')
	}
})
function delmod(de){
	$(de).parents('tr').remove()
}
</script>